<template>
	<view>
		<view class="item-title">申诉内容</view>
		<vsubmit :msg="msg" @submit="submit"></vsubmit>
	</view>
</template>

<script>
	import submit from './Components/submit';
	export default {
		components: {
			Vsubmit: submit
		},
		data() {
			return {
				msg: '您的申诉将在24小时内受理，若申诉成功会第一时间告知处理结果。请尽量提交完整的申诉描述及材料，感谢您的配合。',
				article_id: '',
				apply_text: '',
				imgList: [],
				type: 1
			}
		},
		onLoad(e) {
			this.article_id = e.article_id;
			this.type = e.type;
		},
		methods: {
			submit(data) {
				this.apply_text = data.apply_text;
				this.imgList = data.imgList;
				var url = '';
				var data = {
					content: this.apply_text
				}
				if (this.type == 1) {
					url = 'user/wisdom.Users/appealArticle';
					data.article_id = this.article_id;
				} else if (this.type == 2) {
					url = 'user/video.Lists/appealVideo';
					data.video_id = this.article_id;
				}
				if (!this.apply_text) {
					uni.showToast({
						title: '请填写描述内容',
						icon: 'none'
					})
				} else if (this.imgList.length == 0) {
					this.$zapi.apiPost(url, data).then(res => {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							})
						}, 1000)
					})
				} else if (this.imgList.length > 0) {
					uni.showLoading({
						title: '提交中'
					})
					var imgarr = []
					for (let i = 0; i < this.imgList.length; i++) {
						let jsonobj = {}
						jsonobj.name = "file[" + i + "]"
						jsonobj.uri = this.imgList[i]
						imgarr.push(jsonobj)
					}
					data['file[]'] = imgarr;
					var _this = this;
					_this.$zapi.apifile(url,data).then(res=>{
						uni.hideLoading();
						let data = JSON.parse(res.data);
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 1000
						})
						setTimeout(function() {
							uni.navigateBack({
								delta: 2
							})
						}, 1000)
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F6F6F6;
	}

	.item-title {
		padding: 20upx;
		color: #999999;
	}
</style>
